package view;

import javax.swing.JPanel;
import javax.swing.JTextField;

import controller.Controller;
import po.Student;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.ParseException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Dialog extends JDialog{
	private Controller controller;
	private Student stu;
	private JTextField studentIdTextField,nameTextField,birthdatTextField,phoneNumberTextField,addressTextField,emailTextField,roomNameTextField;
	private JTextField textField[] = {studentIdTextField,nameTextField,birthdatTextField,phoneNumberTextField,addressTextField,emailTextField,roomNameTextField};
	private JButton confirmButton;
	private JComboBox<String> yearDate,monthDate,dayDate;
	public Dialog(LoginPanel loginPanel, String title, Student stu) {
		this.controller = loginPanel.getController();
		this.controller. setStudentAddDialog(this);
//		yearDate = new JComboBox<String>();
//		monthDate = new JComboBox<String>();
//		dayDate = new JComboBox<String>();
		this.setTitle(title);
		this.stu = stu;
		this.getAddAndUpdatePanel();
		this.setModal(true);//指定此对话框是否应该是模态的
		this.setSize(270, 420);//宽 高
		this.setLocationRelativeTo(null);//将窗口放在正中间
		this.setVisible(true);
		this.validate();
	}
	public void getAddAndUpdatePanel() {
		this.setLayout(null);
		String[] titles = {"学号","姓名","生日","电话","地址","邮箱","房名"};
		JLabel label[] = new JLabel[7];		
		if("添加".equals(this.getTitle())) {
			for(int i = 0;i<textField.length;i++) {
				textField[i] = new JTextField();
			}
			confirmButton  = new JButton("确定");
			confirmButton.setActionCommand("addButton");
		}
		else{
			textField[0] = new JTextField(stu.getStudentId(),12);
			textField[1] = new JTextField(stu.getStudentName(),12);
			textField[2] = new JTextField(String.valueOf(stu.getStudentBirthday()),12);
			textField[3] = new JTextField(stu.getStudentTelephoneNumber(),12);
			textField[4] = new JTextField(stu.getStudentAddress(),12);
			textField[5] = new JTextField(stu.getStudentEmail(),12);
			textField[6] = new JTextField(stu.getRoom().getRoomName(),12);
			confirmButton  = new JButton("确定");
			confirmButton.setActionCommand("updateButton");
		}
		CalendarPanel p = new CalendarPanel(textField[2], "yyyy-MM-dd");
		p.initCalendarPanel(); 
		this.getContentPane().add(p);
		for(int i=0;i<label.length;i++) {
			label[i] = new JLabel(titles[i]+" ");
			label[i].setBounds(40,40*i+10,50,50);
			this.getContentPane().add(label[i]);//返回此对话框的 contentPane对象
		}
		for(int i=0;i<7;i++) {
			textField[i].setBounds(75,40*i+25,150,20);
			this.getContentPane().add(textField[i]);
		}
		confirmButton.setBounds(100, 310, 70, 35);
		confirmButton.addActionListener(controller);
		this.getContentPane().add(confirmButton);
//		panel.add(confirmButton);
//		yearDate.addItem("选择年份");
//		String a[] = {"1999","2000","2001","2002","2003"};
//		for(int i=0;i<a.length;i++) {
//			yearDate.addItem(a[i]);
//		}
//		monthDate.addItem("选择月份");	
//		for(int i=1;i<=12;i++) {
//			String b = String.valueOf(i);
//			monthDate.addItem(b);
//		}
//		dayDate.addItem("选择日期");
//		for(int i=1;i<=31;i++) {
//			String c = String.valueOf(i);
//			dayDate.addItem(c);
//		}
//		panel.add(yearDate);
//		panel.add(monthDate);
//		panel.add(dayDate);
//		yearDate.addItemListener(controller);
//		monthDate.addItemListener(controller);
//		dayDate.addItemListener(controller);
	}
	public Controller getController() {
		return controller;
	}
	public Student getStu() {
		return stu;
	}
	public JTextField getStudentIdTextField() {
		return textField[0];
	}
	public JTextField getNameTextField() {
		return textField[1];
	}
	public JTextField getBirthdatTextField() {
		return textField[2];
	}
	public JTextField getPhoneNumberTextField() {
		return textField[3];
	}
	public JTextField getAddressTextField() {
		return textField[4];
	}
	public JTextField getEmailTextField() {
		return textField[5];
	}
	public JTextField getRoomNameTextField() {
		return textField[6];
	}
	public JButton getConfirmButton() {
		return confirmButton;
	}
	public JComboBox<String> getYearDate() {
		return yearDate;
	}
	public JComboBox<String> getMonthDate() {
		return monthDate;
	}
	public JComboBox<String> getDayDate() {
		return dayDate;
	}
	
}
